#!/bin/bash
set -x
CREATE_BRANCH=false;
if [ $1 = "-n" ];then
	if [ ! -z $2 ];then
		CREATE_BRANCH=true;
		BRANCH_NAME=$2;
	else
		BRANCH_NAME=$1
	fi
else
	BRANCH_NAME=$1
fi
P=`pwd`
for i in `cat .repo/project.list`;do
	echo "Processing $i"
	cd $P/$i
	if [ $CREATE_BRANCH = "true" ];then
		git branch $BRANCH_NAME
	fi
		git checkout $BRANCH_NAME
	if [ ! $? -eq 0 ];then
		echo "ERROR switching:$i" | tee /tmp/switch_branch.log
	fi	
done
set +x
